if [ ! $# == 3 ];then
        echo "Usage:./${0} \$1  $2 $3"
        echo "apache-tomcat.sh 端口号  应用名称 用户名"
        exit
fi

#应用的端口
port=$1
#应用项目名称
item=$2
#用户名
user=$3
echo "JDK 1.8.71 安装"
#curl -s https://gitee.com/zjkguo/ywjb/raw/master/jdk1.8.71.sh|sh

echo "tomcat-8.5.39安装..."
#下载apache-tomcat-8.5.31.tar.gz源包
#wget https://mirrors.tuna.tsinghua.edu.cn/apache/tomcat/tomcat-8/v8.5.37/bin/apache-tomcat-8.5.37.tar.gz
wget http://files.git.oschina.net/group1/M00/07/15/PaAvDFybHneABH2aAJOXJdJ99NU8781.gz  -O apache-tomcat-8.5.39.tar.gz
tar -zxvf  apache-tomcat-8.5.39.tar.gz  -C /usr/local/  && mv /usr/local/apache-tomcat-8.5.39 /usr/local/tomcat_${item}
wget  https://gitee.com/zjkguo/ywjb/raw/master/soft/server.xml-8.5 -O /usr/local/tomcat_${item}/conf/server.xml
wget https://gitee.com/zjkguo/ywjb/raw/master/soft/tomcat_team -O /etc/init.d/tomcat_${item}

#修改端口
echo $port $item
sed -i "s/8080/${port}/g" /usr/local/tomcat_${item}/conf/server.xml
sed -i "s/item/${item}/g" /usr/local/tomcat_${item}/conf/server.xml
#修改自启动脚本
sed -i "s/item/${item}/g" /etc/init.d/tomcat_${item}
chmod +x  /etc/init.d/tomcat_${item}.sh
#logs 日志
rm -rf /usr/local/tomcat_${item}/logs

if [ ! -d "/data/logs${item}" ];then
mkdir -p /data/logs/${item}
else
echo "logs文件夹已经存在"
fi
ln -s /data/logs/${item} /usr/local/tomcat_${item}/logs 

if [ ! -d "/data/www/${item}" ];then
mkdir -p /data/www/${item}
else
echo "${item}文件夹已经存在"
fi

#新建用户
id $user >& /dev/null  
if [ $? -ne 0 ]  
then  
   useradd -g  $user  
fi 

#修改权限
chown -R $user:$user /usr/local/tomcat_${item}  
chown -R $user:$user /data/www
chown  -R $user:$user  /etc/init.d/tomcat_${item}.sh
echo "tomcat_${item}部署路径：/usr/local/"
echo "端口:${port}"
echo "启动脚本：/etc/init.d/tomcat_${item}"
echo "新增用户：$user"
